//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_fillRecruit.sqf"
#include "x_setup.sqf"

#include "x_uiinc.sqf"

private ["_control", "_pic", "_index", "_control2", "_tt"];
disableSerialization;
_control = __uiGetVar(GVAR(RECRUIT_DIALOG)) displayCtrl 1000;
lbClear _control;

{
	_ipic = getText (configFile/"cfgVehicles"/_x/"picture");
	_pic = if (_ipic == "") then {
		"#(argb,8,8,3)color(1,1,1,0)"
	} else {
		getText(configFile/"CfgVehicleIcons"/_ipic)
	};
	_index = _control lbAdd ([_x,0] call FUNC(GetDisplayName));
	_control lbSetPicture [_index, _pic];
	_control lbSetColor [_index, [1, 1, 0, 0.8]];
} forEach GVAR(UnitsToRecruit);

_control lbSetCurSel 0;

GVAR(current_ai_num) = 0;
GVAR(current_ai_units) = [];
{
	if (!isPlayer _x && {alive _x}) then {
		__INC(GVAR(current_ai_num));
		GVAR(current_ai_units) set [count GVAR(current_ai_units), _x];
	};
} forEach units group player;

_control2 = __uiGetVar(GVAR(RECRUIT_DIALOG)) displayCtrl 1030;
_control2 ctrlSetText format [(localize "STR_DOM_MISSIONSTRING_693"), GVAR(current_ai_num), GVAR(max_ai)];

_control = __uiGetVar(GVAR(RECRUIT_DIALOG)) displayCtrl 1001;
lbClear _control;
{
	_tt = typeOf _x;
	_pic = getText (configFile/"cfgVehicles"/_tt/"picture");
	_index = _control lbAdd ([_tt,0] call FUNC(GetDisplayName));
	_control lbSetPicture [_index, _pic];
	_control lbSetColor [_index, [1, 1, 0, 0.8]];
} forEach GVAR(current_ai_units);

if (count GVAR(current_ai_units) > 0) then {
	_control lbSetCurSel 0;
};

if (GVAR(current_ai_num) == 0) then {
	(__uiGetVar(GVAR(RECRUIT_DIALOG)) displayCtrl 1011) ctrlShow false;
	(__uiGetVar(GVAR(RECRUIT_DIALOG)) displayCtrl 1012) ctrlShow false;
};
if (GVAR(current_ai_num) == GVAR(max_ai)) then {
	(__uiGetVar(GVAR(RECRUIT_DIALOG)) displayCtrl 1010) ctrlShow false;
};